<template>
  <el-form ref="form"
           :inline="true"
           :model="row"
           :rules="rules">
    <el-form-item label="部门名称"
                  prop="name">
      <el-input v-model="row.name"
                maxlength="10"
                placeholder="请输入部门名称" />
    </el-form-item>
    <el-form-item>
      <el-button :loading="loading"
                 type="primary"
                 @click="handleFormSubmit">
        保存
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  props: {
    row: {
      default: Object,
      type: Object
    },
    loading: {
      default: false,
      type: Boolean
    }
  },
  data() {
    return {
      rules: {
        name: [{ required: true, message: '请输入真实姓名', trigger: 'blur' }]
      }
    }
  },
  methods: {
    handleFormSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('submit', this.row)
        }
      })
    }
  }
}
</script>
